<template>
	<view class="container">
		<view class="history_type">	
			<view class="img">
				<image src="../../static/icon/leixing.png"></image>
			</view>
			<view class="type">				
				交易类型：
			</view>						
			<view class="picker">
				<picker @change="bindPickerChange" :value="index" :range="array">
					<view>{{array[index]}}</view>
				</picker>
			</view>
			<view class="img">
				&gt;
			</view>
		</view>
		
		<view class="main">			
			<view class="history-item" v-for="(item,index) in historyList" :key="item.id">
				<view>
					类型：{{item.operationType}}
				</view>
				<view>
					支付：{{item.payOut}}
				</view>
				<view>
					收款：{{item.payIn}}
				</view>
				<view>
					金额：{{item.amount|MoneyFormat}}
				</view>
				<view>
					时间：{{item.operationTime|formatDate}}
				</view>
			</view>			
		</view>
	</view>
</template>

<script>
	import Global from '../../common/global.js'
	import {formatDate} from '../../common/filter.js'
	
	export default {
		data() {
			return {
				array: ['全部交易记录','支付','充值','提现','转账','收钱'],
				index: 0,
				customerNumber:'',
				historyList:[],
				pageNum:1,
				pageSize:10,
				pageCount:''
			}
		},
		methods: {
			// 选择框事件
			bindPickerChange: function(e) {
			    console.log('picker发送选择改变，携带值为', e.target.value)
			    this.index = e.target.value
				
				this.historyList = []
				this.pageNum = 1
				this.getHistoryList()
			},
			//获得历史交易交易
			getHistoryList(){			
				uni.request({
					url: Global.BASE_URL + '/ewallet/queryHistoryByPage',
					header:{
						'content-type': 'application/x-www-form-urlencoded'
					},
					data:{
						customerNumber:this.customerNumber,
						operationType:this.array[this.index]=='全部交易记录'?'':this.array[this.index],
						pageNum:this.pageNum,
						pageSize:this.pageSize
					},
					method:'POST',
					success:(res)=>{ //注意使用箭头函数	 
						console.log(res)						
						this.pageCount = res.data.pages
						this.historyList.push(...res.data.list)
					},
					fail(err) {
						uni.showToast({
							title:'查询用历史交易记录接口调用失败',
							icon:'none'
						})
					}
				})				
			}
		},
		onLoad() {	
						
		},
		onShow() {
			//读取出客户编号
			this.customerNumber = uni.getStorageSync('customerNumber')
			
			this.index = 0
			this.historyList = []
			this.pageNum = 1
			this.getHistoryList()
		},
		onReachBottom(){
			console.log('到达底部改翻页了')
			
			if (this.pageNum == this.pageCount) {
				
				uni.showToast({
					title:'没有更多数据了',
					icon:'none'
				})
					
				return;
			}			
			
			this.pageNum ++
			this.getHistoryList()
		},
		filters:{
			formatDate (time) { //日期时间过滤器
				let date = new Date(time)
				return formatDate(date, 'yyyy-MM-dd hh:mm')			
			}
		}
	}
</script>

<style>
	page {
		background: #EDEDED;
	}
	
	.container {
		/* padding: 15rpx; */
	}
	
	.history_type {
		width: 750rpx;
		height: 100rpx;
		line-height: 100rpx;
		display: flex;		
		align-items: center;		
		justify-content: center;
		background-color: #FFFFFF;
		font-size: 36rpx;	
		color: #333333;
		position: fixed;		
		top:0;
		/*#ifdef H5*/
		top: 44px;//适配网页
		/*#endif*/
	}
	
	.history_type .img {				
		margin-right: 20rpx;
	}
		
	.history_type image {
		display: block;
		width: 70rpx;
		height: 70rpx;
	}
	
	.main {
		padding: 15rpx;
		color: #ffffff;
		font-size: 30rpx;
		margin-top: 100rpx;
	}
	
	.main .history-item {
		padding: 15rpx;
		background: #F0AD4E;
		border-radius: 15rpx;
		margin-top: 30rpx;
	}	
	
</style>